package com.sservice.web.controller.wx;

import com.sservice.base.entity.dto.BaseResult;
import com.sservice.base.entity.dto.ListResult;
import com.sservice.base.entity.dto.Pagination;
import com.sservice.model.entity.Info;
import com.sservice.model.vo.InfoVo;
import com.sservice.service.service.IInfoService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/wx/info")
public class InfoWxController {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Autowired
    private IInfoService dataService;

    @ResponseBody
    @RequestMapping(value = "/get", method = RequestMethod.GET)
    public BaseResult<Info> get(Info arg) {
        Info service_res = dataService.selectByPrimaryKey(arg.getId());
        BaseResult<Info> res = new BaseResult<Info>(true, service_res);
        return res;
    }

    /***
     * 分页查询
     * @param arg
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/query", method = RequestMethod.GET)
    public ListResult query(InfoVo arg) {
        List<Info> list = dataService.queryByPage(arg);
        int total = dataService.queryCount(arg);

        Pagination page = new Pagination(arg.getPage(), total, arg.getSize());
        System.out.println("Size:" + arg.getSize());
        System.out.println("getSortField:" + arg.getSortField());
        ListResult res = new ListResult(true, list);
        res.setPage(page);
        return res;
    }
}
